<template>
	<view class="box-main">

		<view class="box-top">
			<image style="width: 100%;" :src="$timer.ensureUrl(itemObj.bg_image)" mode="widthFix"></image>
		</view>


		<view style="height: 150rpx;"></view>


		<!-- 二维码弹窗 -->
		<add-wx @close='closeOpenQr' ref="addwxRef"></add-wx>
		<!-- end -->

		<!-- 底部导航栏 -->
		<view v-if="customTabShow " class="box-bar  sb">
			<view class="flex ac">
				<view @click="phoneClick('4007180878')" class="flex ac jc fc">
					<view class="">
						<text class="iconfont-yjgs " style="font-size: 46rpx;">
							&#xe6ea;
						</text>
					</view>
					<view>
						<text class="fs-22">电话咨询</text>
					</view>
				</view>
				<view @click="openQr" class="flex ac jc fc ml-50">
					<view class="">
						<text class="iconfont icon-weixin1 " style="font-size: 46rpx;color: #51D25F;"></text>
					</view>
					<view>
						<text class="fs-22">微信</text>
					</view>
				</view>
			</view>

			<view class="flex ac" style=" width: 66%;">
				<view @click="toPage('服务申请')" class="box-bar-btn mr-20" style="flex: 1;">
					服务案例
				</view>
			</view>
		</view>
		<!-- end -->

		<!-- 发布按钮 -->
		<!-- <view @click="toPage('发布按钮')" class="box-send-btn">
			<text style="font-size: 48rpx;" class="iconfont-yjgs">
				&#xe641;
			</text>
		</view> -->
		<!-- end -->

	</view>
</template>

<script>
	import emptyPage from '@/pages/extend/components/emptyPage.vue'
	import parser from "@/components/jyf-parser/jyf-parser";
	import {
		serviceList,
		serviceDetail,
		serviceAppraiseList
	} from "@/api/extend.js"
	import addWx from '@/pages/extend/components/addWx/addWx.vue'
	export default {
		components: {
			addWx,
			"jyf-parser": parser,
			emptyPage
		},
		data() {
			return {
				commonList: [],
				tagStyle: {
					img: 'width:100%;display:block;'
				},
				current: 0,
				options: {},
				itemObj: {},
				typeList: [],
				customTabShow: true,
			}
		},
		computed: {
			myCompany() {
				return this.$store.state.extend.myCompany;
			},
			uid() {
				return this.$store.state.app.uid;
			}
		},
		onLoad(options) {
			this.options = options;
			this.serviceListFunc({
				id: options.category_id
			});
		},
		/**
		 * 用户点击右上角分享
		 */
		// #ifdef MP
		onShareAppMessage: function() {
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			return {
				title: this.typeList[this.current]['title'] || '平台服务',
				imageUrl: "",
				path: `/pages/extend/service/service_case?uid=${this.uid}&category_id=${this.options.category_id}`
			};
		},
		onShareTimeline: function() {
			let that = this;
			return {
				title: this.typeList[this.current]['title'] || '平台服务',
				query: {

				},
				imageUrl: ''
			};
		},
		// #endif
		methods: {
			selectType(item, index) {
				if (this.current == index) return;
				this.current = index;
				uni.setNavigationBarTitle({
					title: this.typeList[index]['title'] || '平台服务'
				})
				this.serviceDetailFunc({
					id: item['category_id']
				});
				this.serviceAppraiseListFunc();
			},
			showLongTxt(item, index) {
				item.contentShow = item.content;
				item.isShowMoretxt = false;
				this.$forceUpdate();
			},
			preViewImgCase(url) {
				uni.previewImage({
					urls: [url],
					current: 0
				})
			},
			preViewImg(list, index) {
				uni.previewImage({
					urls: list,
					current: index
				})
			},

			serviceAppraiseListFunc() {
				serviceAppraiseList({
					limit: 8,
					page: 1,
					category_id: this.typeList[this.current]['category_id']
				}).then(res => {
					this.commonList = res.data.data;
					res.data.data.forEach((_, index, arr) => {
						let item = arr[index];
						item.isShowMoretxt = false;
						if (item.content.length > 50) {
							item.contentShow = item.content.substr(0, 50) + '...';
							item.isShowMoretxt = true
						} else {
							item.contentShow = item.content;
							item.isShowMoretxt = false
						}
					})

				})
			},
			phoneClick(phone) {
				uni.makePhoneCall({
					phoneNumber: phone,
					success: () => {},
					fail: (err) => {}
				});
			},
			serviceDetailFunc({
				id
			}) {
				serviceDetail({
					id
				}).then(res => {
					this.itemObj = res.data;
				})
			},
			serviceListFunc({
				id
			}) {
				serviceList({
					id
				}).then(res => {
					this.typeList = res.data;
					this.$store.commit("SET_ServiceType", res.data);
					if (this.typeList.length > 0) {
						this.serviceDetailFunc({
							id: res.data[0]['category_id']
						});
						uni.setNavigationBarTitle({
							title: res.data[0]['title'] || '平台服务'
						})
						this.serviceAppraiseListFunc();
					}
				})
			},
			toPage(tag) {
				if (tag == '服务申请') {



					if ([7, 15].includes(Number(this.options.category_id))) { // 品牌策划
						uni.switchTab({
							url: '/pages/service/index'
						})
						return;
					}

					if (this.options.category_id == 13) { // 信用服务
						uni.switchTab({
							url: '/pages/index/index'
						})
						return;
					}

					if (this.options.category_id == 14) { // 商会
						uni.navigateTo({
							url: '/pages/project_model/index_v2'
						})
						return;
					}




					// if (this.options.category_id == 3) { //购买名片
					// 	uni.navigateTo({
					// 		url: '/pages/extend/user_vip/user_vip'
					// 	})
					// 	return;
					// }

					// let obj = this.typeList[this.current];
					// uni.navigateTo({
					// 	url: `/pages/extend/service/index_send?category_id=${obj.category_id}&_index=${this.current}`
					// })
					// return;
				}
				if (tag == '发布按钮') {
					let obj = this.typeList[this.current];
					uni.navigateTo({
						url: '/pages/extend/service/case_send?category_id=' + obj.category_id
					})
					return;
				}
			},
			closeOpenQr() {
				this.customTabShow = true;
			},
			openQr() {
				this.$refs.addwxRef.popupQr('bottom');
				this.customTabShow = false;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box-form-imgb {
		display: grid;
		grid-template-columns: 1fr 1fr 1fr;
		grid-gap: 20rpx;
	}

	.box-label-s {
		border-radius: 6rpx;
		margin-right: 20rpx;
		text-align: center;
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-top: 2rpx;
		padding-bottom: 2rpx;
		width: fit-content;
		background-color: rgba(0, 102, 255, .15);
		color: #126EF9;
	}

	.box-label {
		border-radius: 6rpx;
		margin-right: 20rpx;
		text-align: center;
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-top: 2rpx;
		padding-bottom: 2rpx;
		width: fit-content;
		border: 1rpx solid #126EF9;
		color: #126EF9;
	}

	.box-comm-card {
		margin-bottom: 20rpx;
		border-radius: 10rpx;
		position: relative;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.box-form-img {
		display: grid;
		grid-template-columns: 1fr 1fr 1fr;
		grid-gap: 20rpx;
	}

	.box-send-btn {
		z-index: 20;
		position: fixed;
		right: 50rpx;
		bottom: 350rpx;
		background-color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		color: white;
		width: 90rpx;
		height: 90rpx;
		border-radius: 30rpx;
		font-size: 50rpx;
	}

	.box-title {
		font-size: 30rpx;
		width: fit-content;
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-top: 6rpx;
		padding-bottom: 6rpx;
		background-color: #1961EB;
		color: white;
		border-radius: 60rpx;
	}

	.box-major {
		border: 1px solid white;
		border-radius: 30rpx;
		padding: 20rpx;
		box-sizing: border-box;
		width: 100%;
		background: rgba(255, 255, 255, 0.35);
	}

	.box-centent {
		padding: 30rpx;
		min-height: 80vh;
		width: 100%;
		background: linear-gradient(to bottom, rgba(255, 255, 255, .2) -100%, rgba(184, 229, 255, 0.5) 100%);
		// background-color: rgba(184, 229, 255, .4);
		position: relative;
		top: -160rpx;
	}

	.box-bar-btn {
		border-radius: 8rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 30rpx;
		font-weight: 550;
		color: white;
		height: 100%;
		background-color: #0066FF;
	}

	.box-bar-btn:active {
		opacity: .5;
	}

	.box-bar {
		padding: 20rpx;
		box-sizing: border-box;
		border-top: 1px solid #F3F3F3;
		z-index: 99;
		left: 0;
		box-shadow: 1px -3px 20rpx rgba(0, 0, 0, .12), 0 0 3rpx rgba(0, 0, 0, .04);
		color: #292929;
		display: flex;
		align-items: center;
		bottom: 0;
		position: fixed;
		width: 100%;
		background-color: #FFFFFF;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 20rpx); ///兼容 IOS<11.2/
		padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx); ///兼容 IOS>11.2/
		height: calc(120rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		height: calc(120rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
	}

	.box-main {}
</style>